package com.nulldev.util.net.proxy.filtering;

import java.util.LinkedList;

import com.nulldev.util.java.DataSet;

public class ProxyFilterManager {
	private static final LinkedList<ProxyFilter> filters = new LinkedList<ProxyFilter>();
	
	public static boolean addFilter(final ProxyFilter pf) {
		return filters.add(pf);
	}
	
	public static DataSet<Boolean, String> allowed(final String url, final String domain) {
		if (filters.isEmpty()) {
			return new DataSet<Boolean, String>(true, "URL was not blocked.");
		}
		for (final ProxyFilter filter : (LinkedList<ProxyFilter>) filters.clone()) {
			if (!filter.allowed(url, domain)) {
				return new DataSet<Boolean, String>(false, "URL was blocked by " + filter.getID() + ".");
			}
		}
		return new DataSet<Boolean, String>(true, "URL was not blocked.");
	}
}
